This sample shows how to use the Network Setup library (as introduced in Mac OS 8.5) to determine whether opening a TCP/IP provider will cause a modem to dial. If the Network Setup library is not available, the sample will read the "TCP/IP Preferences" file directly.
Packing List
The sample contains the following items:
• TestOTTCPWillDial.µ — A project that builds a test program that demonstrates the use of OTTCPWillDial.
• OTTCPWillDial — A compiled version of the above.
• TestOTTCPWillDial.c — The source code to the test program.
• OTTCPWillDial.h — A header that describes the (very basic) interface to OTTCPWillDial.
• OTTCPWillDial.c — Source code to OTTCPWillDial.
• Network Setup SDK Bits — Pre-release interfaces and libraries from the Network Setup SDK.
Using the Sample
To use the sample, simple run the OTTCPWillDial application. It will tell you whether opening a TCP/IP provider will dial the modem.
Building the Sample
The sample was built using the CodeWarrior Pro 4 C compiler.
To build the sample, the first thing you have to do is grab all the OT interface files from the OT SDK and put them in one folder. The interfaces that come with CodeWarrior don’t include all the low-level APIs that you will need. Similarly, you should group all the OT libraries in the same folder. Then modify the access paths for the project to point those folders.
Then just open the project, select the “OTTCPWillDial” target, and choose Make from the Project menu. This will build the OTTCPWillDial application.
How it Works
OTTCPWillDial contains two code paths. If the Network Setup library is not available, the OTTCPWillDial will look read the information directly out of the "TCP/IP Prefereces" file in the Prefererences folder. If Network Setup is installed, OTTCPWillDial will use it to read the information.
Before you look at the code, you need some idea of the Network Setup 'big picture'. At the time of writing, there are four sources for information:
1. The document "NetworkSetupBigPicture.html" (in the "Network Setup SDK Bits" folder) contains a one page summary of the Network Setup concepts.
2. The Network Setup header files contain numerous comments describing the API.
3. The "Open Tpt TCP/IP Dev. Note" (part of the OT SDK) contains a description of the original "TCP/IP Preferences" file format. Many of the preferences in the Network Setup database are byte-for-byte compatible with their corresponding resources described in that document.
4. The Network Setup Scripting scripting addition contains a dictionary that roughly reflects the contents of the Network Setup database. You can learn a lot about how the database is structured by reading through the dictionary and sending experimental queries from AppleScript.
Caveats
The current implementation does not look to see whether the modem link is set to "Connect automatically when starting TCP/IP applications." Doing so would require special case code for ARA 3.x versus OT/PPP versus FreePPP etc. Instead, the code makes the simplifying assumption that any modem link layer (ie devices of type kOTMDEVDevice, kOTSLIPDevice, or kOTPPPDevice) is a potential dial.
The code is based on pre-release Network Setup interfaces and libraries. It's likely that some file names and structure names will change before the final interfaces are released.
Credits and Version History
If you find any problems with this sample, mail <DTS@apple.com> with “Attn: Quinn” as the first line of your mail and I’ll try to fix them up.
1.0d1 and 1.0d2 (Apr 1998) shipped to a number of Apple internal developers.
1.0b1 (Sep 1998) was released for internal review. It was works correctly with Mac OS 8.5 final.
1.0b2 (Oct 1998) was the first shipping version. It's was an update to use the latest Network Setup interfaces and libraries.